<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/js/jquery-3.3.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/md5.js"></script>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="/layer/layer.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <style>
        .col-center-block {
            float: none;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
</head>
<body>
<br/>
<br/>
<br/>
<div class="col-xs-6 col-md-6  col-center-block">
    <form class="form-horizontal">
        <div class="form-group">
            <label for="in_uid" class="control-label col-sm-2">手机号</label>
            <div class="col-sm-6">
                <input type="text" placeholder="手机号" class="form-control" id="in_uid"/>
            </div>
        </div>
        <div class="form-group">
            <label for="in_upwd" class="control-label col-sm-2">密码</label>
            <div class="col-sm-6">
                <input type="password" placeholder="密码" class="form-control" id="in_upwd">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-12">
                <button type="button" class="btn btn-danger" id="cancel" style="width: 120px">取消</button>
                <button type="button" class="btn btn-success" id="login" style="width: 120px; margin-left: 20px">登录
                </button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    $(function () {
        var ref = document.referrer == "" ? "/html/goods_list.html" : document.referrer;
        var timer;
        console.log(ref);
        $("#login").click(function () {
            var uid = $("#in_uid").val();
            var upwd = $("#in_upwd").val();
            upwd = hex_md5(upwd);
            $.ajax({
                type: "POST",
                url: "/user/login",
                data: {
                    "userId": uid,
                    "userPassWord": upwd
                },
                success: function (result) {
                    console.log(result);
                    console.log(result.code);
                    if(result.code != 10001) {
                        layer.msg(result.message);
                    } else {
                        layer.msg("登录成功");
                        getUser(uid);
                        console.log(user);
                        timer = setTimeout(function () {
                            jump();
                        }, 500);
                    }
                }
            });
        });
        $("#cancel").click(function () {
            jump();
        });
        function getUser(uid) {
            $.ajax({
               type: "GET",
               url: "/user/" + uid,
               success: function (result) {
                   if(result.code == 10001) {
                        user.user_id = result.data.userId;
                        user.user_name = result.data.userName;
                        user.user_balance = result.data.userBalance;
                   }
               }
            });
        }
        function jump() {
            clearTimeout(timer);
            window.location.href = ref;
        }
    });
</script>
</html>